<template>
	<el-dialog
		width="35%"
		:title="title"
		:visible.sync="infoComShow"
		:before-close="clear"
		append-to-body
		:close-on-click-modal="false"
		:close-on-press-escape="false"
	>
		<el-form :model="investStyle" ref="investStyle" label-width="80px">
			<el-form-item label="投资代码">
				<el-select :disabled="title === '复核'" v-model="investStyle.managerInfoId" clearable filterable style="width: 100%">
					<el-option key="" label="--全部--" value=""> </el-option>
					<el-option v-for="(item, index) in managerList" :key="index + 'a'" :label="item.oaId" :value="item.managerId"> </el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="投资风格" required>
				<el-input v-model.trim="investStyle.investmentStyle" :disabled="title == '复核'"></el-input>
			</el-form-item>
			<el-form-item label=" " v-if="!!checkRemark">
				<span style="color: red">驳回备注：{{ checkRemark }}</span>
			</el-form-item>
		</el-form>
		<div slot="footer">
			<el-button size="small" type="primary" v-if="title !== '复核'" @click="clear">取 消</el-button>
			<el-button size="small" type="primary" v-if="title !== '复核'" @click="confirm">确 定</el-button>

			<el-button size="small" type="primary" v-if="title == '复核'" @click="formCom('驳回', 2)">驳回</el-button>
			<el-button size="small" type="primary" v-if="title == '复核'" @click="formCom('确认', 1)">确认无误 </el-button>
		</div>
	</el-dialog>
</template>
<script>
import { addStyle, editStyle, checkStyle, getFunManAll, seachSheckRemark } from '@/api/productApi/assessment'
export default {
	props: {
		title: {
			type: String,
			default: ''
		},
		infoComShow: {
			type: Boolean,
			default: false
		},
		infoCom: {
			type: Function,
			default: Function
		},
		propGetData: {
			type: Function,
			default: Function
		}
	},
	data() {
		return {
			managerList: [],
			investStyle: {
				managerInfoId: '',
				investmentStyle: ''
			},
			checkRemark: ''
		}
	},
	methods: {
		edit(data) {
			this.investStyle = JSON.parse(data)
			if (this.investStyle.checkState === '2') {
				seachSheckRemark({ checkState: '2', mainId: this.investStyle.pkId }).then(res => {
					this.checkRemark = res.data.body[0].checkRemark
				})
			}
		},
		clear() {
			this.checkRemark = ''
			this.$emit('infoCom')
			this.investStyle = {
				managerInfoId: '',
				investmentStyle: ''
			}
		},
		confirm() {
			if (this.investStyle.investmentStyle) {
				if (this.title === '新增') {
					addStyle(this.investStyle).then(res => {
						if (res.msgCode === 'Y') {
							this.$message({ message: res.msg, customClass: 'el-messageClass', type: 'success' })
							this.clear()
							this.$emit('propGetData')
						}
					})
				} else if (this.title === '编辑') {
					const obj = {
						pkId: this.investStyle.pkId ? this.investStyle.pkId : '',
						managerInfoId: this.investStyle.managerInfoId,
						investmentStyle: this.investStyle.investmentStyle
					}
					editStyle(obj).then(res => {
						if (res.msgCode === 'Y') {
							this.$message({ message: res.msg, customClass: 'el-messageClass', type: 'success' })
							this.clear()
							this.$emit('propGetData')
						}
					})
				}
			} else {
				this.$message({ type: 'warning', customClass: 'el-messageClass', message: '请填写相关信息' })
			}
		},
		formCom(type, state) {
			this.investStyle.checkState = state
			if (type === '驳回') {
				this.$prompt('驳回原因', '提示', {
					confirmButtonText: '确定',
					concelButtonText: '取消',
					inputPattern: /[^\\s\ \r\\n]/,
					inputErrorMessage: '请输入驳回原因'
				}).then(({ value }) => {
					this.investStyle.checkRemark = value
					checkStyle(this.investStyle).then(res => {
						if (res.msgCode === 'Y') {
							this.$message({ message: res.msg, customClass: 'el-messageClass', type: 'success' })
							this.clear()
							this.$emit('propGetData')
						}
					})
				})
			} else if (type === '确认') {
				checkStyle(this.investStyle).then(res => {
					if (res.msgCode === 'Y') {
						this.$message({ message: res.msg, customClass: 'el-messageClass', type: 'success' })
						this.clear()
						this.$emit('propGetData')
					}
				})
			}
		},
		getData() {
			getFunManAll({ managerTypeList: ['1', '2'] }).then(res => {
				if (res.msgCode === 'Y') {
					res.data.body.forEach(item => {
						if (!!item.attributes && 'cnname' in item.attributes) {
							item.chineName = item.attributes.cnname[0].replace(/[^\u4e00-\u9fa5]/gi, '')
						} else {
							item.chineName = item.username
						}
					})
					this.managerList = res.data.body.filter(item => !!item.managerId)
				}
			})
		}
	}
}
</script>
<style lang="scss" scoped>
</style>
